package com.ardf.controller;

import com.ardf.common.CodeEnum;
import com.ardf.common.ReturnResult;
import com.ardf.entity.Athlete;
import com.ardf.entity.Team;
import com.ardf.entity.dto.AthleteTeamDto;
import com.ardf.service.ITeamService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ShiYunHao
 * @since 2025-01-06
 */
@RestController
@RequestMapping("/ardf/team")
public class TeamController {
    private final ITeamService teamService;
    public TeamController(ITeamService teamService){
        this.teamService=teamService;
    }

    /**
     * 根据单位id查询接力队伍
     */
    @GetMapping("/getByUnitId")
    public ResponseEntity<List<Team>> getByUnitId(@RequestParam("unitId") Long unitId){
        List<Team> teams = teamService.list(new LambdaQueryWrapper<Team>()
                .eq(Team::getUnitId, unitId));
        return ResponseEntity.ok(teams);
    }

    /**
     * author:容伟洪
     * time:2025-3-7
     * description：根据队伍id查找所有的接力人员
     */
    @GetMapping("/selectAtheleByTId")
    public ResponseEntity<ReturnResult> selectAtheleByTId(@RequestParam("teamId")Long teamId,
                                                          @RequestParam("projectId")Long projectId){
        List<AthleteTeamDto> dtos = teamService.selectAtheleByTId(teamId,projectId);
        ReturnResult result=new ReturnResult(CodeEnum.SUCCESS);
        result.setData(dtos);
        return ResponseEntity.ok(result);
    }

}
